var app = {
	    // Application Constructor
	    initialize: function() {
	        this.bindEvents();
	    },
	    // Bind Event Listeners
	    //
	    // Bind any events that are required on startup. Common events are:
	    // 'load', 'deviceready', 'offline', and 'online'.
	    bindEvents: function() {
	        document.addEventListener('deviceready', this.onDeviceReady, false);
	    },
	    // deviceready Event Handler
	    //
	    // The scope of 'this' is the event. In order to call the 'receivedEvent'
	    // function, we must explicity call 'app.receivedEvent(...);'
	    onDeviceReady: function() {
	        app.receivedEvent('deviceready');
	    },
	    // Update DOM on a Received Event
	    receivedEvent: function(id) {
	        var parentElement = document.getElementById(id);
	        var listeningElement = parentElement.querySelector('.listening');
	        var receivedElement = parentElement.querySelector('.received');
	 
	        listeningElement.setAttribute('style', 'display:none;');
	        receivedElement.setAttribute('style', 'display:block;');
	 
	        console.log('Received Event: ' + id);
	        var pushNotification = window.plugins.pushNotification;
			pushNotification.register(app.successHandler, app.errorHandler,{"senderID":"64300549935","ecb":"app.onNotificationGCM"});
	    },
	    successHandler: function(result) {
	        alert('Todo Correcto! Resultado = '+result)
	    },
	    errorHandler:function(error) {
	        alert(error);
	    },
		onNotificationGCM: function(e) {
	        switch( e.event ) {
	        	case 'registered':
	        		if ( e.regid.length > 0 )
	        		{
	        			console.log(“Regid ” + e.regid);
	        			alert('id de registracion = '+e.regid);
	        			//Cuando se registre le pasamos el regid al input
	        			document.getElementById('regId').value = e.regid;
	        		}
	        		break; 
	      //     case 'registered':
	      //         if ( e.regid.length > 0 ) {
	      //             console.log("Id registro: " + e.regid);
	      //            alert('Id registro:  '+e.regid);
	      //         }
	      //     break;
	            case 'message':
	                alert('Mensaje:  '+e.message+' Contenido: '+e.msgcnt);
	            break;
	            case 'error':
	                alert('GCM error = '+e.msg);
	            break;
	            default:
	                alert('Ocurrió un evento desconocido de GCM');
	            break;
	        }
	    }
	};



